package com.yanqu.road.entity.activity.newyearbag;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class NewYearBagConfig {

    public static long recentRechargeTime = DateHelper.DAY_MILLIONS * 30;       // 取最近x天充值金额
    public static int noticeSize = 30;                                          // 公告长度

    private ActivityInfo activityInfo;              // 活动信息

    private long canOpenTime;                       // 这个时间点后才可以开启红包

    private int tongBaoId;                          // 通宝ID
    private int xianJinId;                          // 现金ID
    private int hongBaoId;                          // 红包ID
    private int fuDaiId;                            // 福袋ID

    private int cashOutTitleLimit;                  // 提现身份限制

    private int deviceTimes;                                        // 每个设备限制x次现金
    private Map<Integer, Integer> deviceChangeWeightMap;            // 设备现金上限后权重变化

    private List<NewYearBagDrawConfig> drawConfigList;              // 奖励
    private List<NewYearBagLimitConfig> limitConfigList;            // 用户获奖限制

    private Map<Integer, List<Integer>> taskTypeMap;                // 任务类型，List<任务类型，概率，触发后加进度，没触发加进度>

    private List<Long> loginRewardTimeList;                         // 每天登录领奖时间
    private String loginReward;                                     // 每天登录领奖奖励
    private int loginRewardDay;                                     // 登录领奖天数限制

    private int shiWuDeviceTimes;                                        // 每个设备限制x次实物
    private Map<Integer, Integer> shiWuDeviceChangeWeightMap;            // 设备实物上限后权重变化

    private int shiWuVipExpLimit;                                   //VIP经验大于X才可抽到实物奖励

    private int openIdUserIdXianJinLimit;                           //一个openId  一个userId 触发现金奖励次数
    private int openIdUserIdShiWuLimit;                             //一个openId  一个userId 触发实物奖励次数

    public void initActivityConfig(Map<String, ActivityConfig> activityConfigMap) {
        canOpenTime = activityConfigMap.get("NEWYEARBAG_WORM_HOUR").getIntValue() * DateHelper.HOUR_MILLIONS
                + activityInfo.getBeginTime() * 1000;
        tongBaoId = activityConfigMap.get("NEWYEARBAG_TONGBAO_ITEM_ID").getIntValue();
        xianJinId = activityConfigMap.get("NEWYEARBAG_CASH_ITEM_ID").getIntValue();
        fuDaiId = activityConfigMap.get("NEWYEARBAG_BAG_ITEM_ID").getIntValue();
        hongBaoId = activityConfigMap.get("NEWYEARBAG_RED_ITEM_ID").getIntValue();
        cashOutTitleLimit = activityConfigMap.get("NEWYEARBAG_TURN_LIMIT").getIntValue();

        List<String> deviceLimitList = activityConfigMap.get("NEWYEARBAG_DEVICE_LIMIT").getStringListValue("#");
        deviceTimes = Integer.valueOf(deviceLimitList.get(0));
        Map<Integer, Integer> map = new ConcurrentHashMap<>();
        for (String tmpStr : StringUtils.stringToStringList(deviceLimitList.get(1), "\\|")) {
            List<Integer> list = StringUtils.stringToIntegerList(tmpStr, "=");
            map.put(list.get(0), list.get(1));
        }
        deviceChangeWeightMap = map;

        Map<Integer, List<Integer>> tmpTaskTypeMap = new ConcurrentHashMap<>();
        for (String taskPercent : activityConfigMap.get("NEWYEARBAG_TASK_PERCENT").getStringListValue("\\|")) {
            List<Integer> list = StringUtils.stringToIntegerList(taskPercent, ";");
            tmpTaskTypeMap.put(list.get(0), list);
        }
        taskTypeMap = tmpTaskTypeMap;

        List<String> loginRewardList = activityConfigMap.get("NEWYEARBAG_LOGIN_REWARD").getStringListValue("\\|");
        loginRewardTimeList = StringUtils.stringToLongList(loginRewardList.get(0), ";").stream().mapToLong(item -> item * DateHelper.MINUTE_MILLIONS).boxed().collect(Collectors.toList());
        loginReward = loginRewardList.get(1);
        loginRewardDay = Integer.valueOf(loginRewardList.get(2));

        List<String> shiWuDeviceLimitList = activityConfigMap.get("NEWYEARBAG_DEVICE_LIMIT2").getStringListValue("#");
        shiWuDeviceTimes = Integer.valueOf(shiWuDeviceLimitList.get(0));
        Map<Integer, Integer> tempMap = new ConcurrentHashMap<>();
        for (String tmpStr : StringUtils.stringToStringList(deviceLimitList.get(1), "\\|")) {
            List<Integer> list = StringUtils.stringToIntegerList(tmpStr, "=");
            tempMap.put(list.get(0), list.get(1));
        }
        shiWuDeviceChangeWeightMap = tempMap;

        shiWuVipExpLimit = activityConfigMap.get("NEWYEARBAG_VIP_LIMIT").getIntValue();

        openIdUserIdXianJinLimit = activityConfigMap.get("NEWYEARBAG_USERID_LIMIT").getIntValue();
        openIdUserIdShiWuLimit = activityConfigMap.get("NEWYEARBAG_USERID_LIMIT2").getIntValue();

    }


    // --------------------------------------------


    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public void setActivityInfo(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    public long getCanOpenTime() {
        return canOpenTime;
    }

    public void setCanOpenTime(long canOpenTime) {
        this.canOpenTime = canOpenTime;
    }

    public int getTongBaoId() {
        return tongBaoId;
    }

    public void setTongBaoId(int tongBaoId) {
        this.tongBaoId = tongBaoId;
    }

    public int getXianJinId() {
        return xianJinId;
    }

    public void setXianJinId(int xianJinId) {
        this.xianJinId = xianJinId;
    }

    public int getHongBaoId() {
        return hongBaoId;
    }

    public void setHongBaoId(int hongBaoId) {
        this.hongBaoId = hongBaoId;
    }

    public int getFuDaiId() {
        return fuDaiId;
    }

    public void setFuDaiId(int fuDaiId) {
        this.fuDaiId = fuDaiId;
    }

    public int getCashOutTitleLimit() {
        return cashOutTitleLimit;
    }

    public void setCashOutTitleLimit(int cashOutTitleLimit) {
        this.cashOutTitleLimit = cashOutTitleLimit;
    }

    public List<NewYearBagDrawConfig> getDrawConfigList() {
        return drawConfigList;
    }

    public void setDrawConfigList(List<NewYearBagDrawConfig> drawConfigList) {
        this.drawConfigList = drawConfigList;
    }

    public List<NewYearBagLimitConfig> getLimitConfigList() {
        return limitConfigList;
    }

    public void setLimitConfigList(List<NewYearBagLimitConfig> limitConfigList) {
        this.limitConfigList = limitConfigList;
    }

    public int getDeviceTimes() {
        return deviceTimes;
    }

    public void setDeviceTimes(int deviceTimes) {
        this.deviceTimes = deviceTimes;
    }

    public Map<Integer, Integer> getDeviceChangeWeightMap() {
        return deviceChangeWeightMap;
    }

    public void setDeviceChangeWeightMap(Map<Integer, Integer> deviceChangeWeightMap) {
        this.deviceChangeWeightMap = deviceChangeWeightMap;
    }

    public Map<Integer, List<Integer>> getTaskTypeMap() {
        return taskTypeMap;
    }

    public void setTaskTypeMap(Map<Integer, List<Integer>> taskTypeMap) {
        this.taskTypeMap = taskTypeMap;
    }

    public List<Long> getLoginRewardTimeList() {
        return loginRewardTimeList;
    }

    public void setLoginRewardTimeList(List<Long> loginRewardTimeList) {
        this.loginRewardTimeList = loginRewardTimeList;
    }

    public String getLoginReward() {
        return loginReward;
    }

    public void setLoginReward(String loginReward) {
        this.loginReward = loginReward;
    }

    public int getLoginRewardDay() {
        return loginRewardDay;
    }

    public void setLoginRewardDay(int loginRewardDay) {
        this.loginRewardDay = loginRewardDay;
    }

    public int getShiWuDeviceTimes() {
        return shiWuDeviceTimes;
    }

    public Map<Integer, Integer> getShiWuDeviceChangeWeightMap() {
        return shiWuDeviceChangeWeightMap;
    }

    public int getShiWuVipExpLimit() {
        return shiWuVipExpLimit;
    }

    public int getOpenIdUserIdXianJinLimit() {
        return openIdUserIdXianJinLimit;
    }

    public int getOpenIdUserIdShiWuLimit() {
        return openIdUserIdShiWuLimit;
    }
}
